package io.gitee.zhangbinhub.admin.oauth.controller.openinner

import io.gitee.zhangbinhub.acp.boot.exceptions.WebException
import io.gitee.zhangbinhub.acp.boot.interfaces.LogAdapter
import io.gitee.zhangbinhub.admin.common.api.CommonPath
import io.gitee.zhangbinhub.admin.common.api.OauthApi
import io.gitee.zhangbinhub.admin.resource.server.base.BaseResourceServerController
import io.gitee.zhangbinhub.admin.common.vo.BooleanInfoVo
import io.gitee.zhangbinhub.admin.oauth.domain.ModuleFuncDomain
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*

/**
 * @author zhang by 01/02/2019
 * @since JDK 11
 */
@Validated
@RestController
@RequestMapping(CommonPath.openInnerBasePath)
@Tag(name = "认证信息（内部开放接口）")
class OpenInnerTokenController @Autowired
constructor(
    logAdapter: LogAdapter,
    private val moduleFuncDomain: ModuleFuncDomain
) : BaseResourceServerController(logAdapter) {
    @Operation(summary = "判断指定用户是否具有指定的权限")
    @GetMapping(
        value = [OauthApi.moduleFunc + "/{userId}/{moduleFuncCode}"],
        produces = [MediaType.APPLICATION_JSON_VALUE]
    )
    @Throws(WebException::class)
    fun userHasModuleFunc(
        @PathVariable userId: String,
        @PathVariable moduleFuncCode: String
    ): ResponseEntity<BooleanInfoVo> =
        ResponseEntity.ok(BooleanInfoVo(result = moduleFuncDomain.hasModuleFunc(userId, moduleFuncCode)))
}
